class Movie < ActiveRecord::Base
	validates_presence_of :title, :description
	validates_uniqueness_of :title
	validates_length_of :description, :minimum => 10
	validates_inclusion_of :rating, :in => %w( G PG PG-13 R NC-17 )

	def appropriate_for_birthdate?(birthdate)
		if 13.years.ago < birthdate then
			%w(G PG).include? rating
		elsif 17.years.ago < birthdate then
			%w(G PG PG-13).include? rating
		else
			true
		end
	end

	def self.find_all_appropriate_for_birthdate(birthdate)
		ratings = []
		if 13.years.ago < birthdate then
			ratings = %w(G PG)
		elsif 17.years.ago < birthdate then
			ratings = %w(G PG PG-13)
		end
		if ratings.empty? then
			find(:all)
		else
			find(:all, :conditions=>{:rating=>ratings})
		end
	end
end
